﻿$(function () {
    var webForm1Tree = $("#WebForm1Tree");

    webForm1Tree.jstree({
        themes: {
            theme: "classic",
            dots: false,
            icons: false
        },
        core: {
            animation: 0
        },

        callback: {
    },

    json_data: {
        ajax: {
            url: "http://localhost:54304/services/ChromeBookmarksService.asmx/bookmarkJsTreeForItemPath",
            type: "POST",
            contentType: "application/json",
            dataType: "json",
            async: "true",
            data: function (n) {
                var result = "{'itemPath':'" + (n.attr ? n.attr("id").replace("node_", "") : "0") + "'}";
                return (result);
            },
            success: function (data) {
            }
        }
    },

    plugins: ["themes", "json_data", "ui", "core", "crrm", "contextmenu"]
});

//#events hook
webForm1Tree.bind("remove.jstree", function (event, data) {
    var id = data.rslt.obj.attr("id");
});

webForm1Tree.bind("create.jstree", function (event, position, type, callback, is_loaded) {
    var newNode = position.rslt;
    var newNodeName = newNode.name;

    var newNodeParent = position.rslt.parent;
    var parentId = newNodeParent.attr("id");
    var parentIdReplaced = parentId.replace("rnode_", "");
    alert("created " + newNodeName + " in:" + parentIdReplaced);
});
webForm1Tree.bind("open_node.jstree", function (event, data) {
    alert("expanded"+data.rslt.obj);
});
});
